use "./data/processed/CE_cleaned_reg.dta",clear 

estimates clear 
eststo clear 

* ==============================
* Table S7. sensitivity tests
* ==============================
local demo_controls r_age r_female c.r_educ i.r_race r_married r_working

local DV pol_one_diff
qui logit `DV' i.year i.state_code `demo_controls' close_election [pw=wt] if a_talkpol > 0 & one == 1, cluster(state_code)
margins, dydx(close_election) post 
	estadd local state_year_fe "Yes"
	estadd local demo_control "Yes" 	 
	estadd local previous_CE "No" 	 
	estadd local CE "5" 	 
	estadd local DV "4"
	estadd local rel_type "All"
estimates store m1

qui logit `DV' i.year i.state_code `demo_controls' close_election lag_close_election [pw=wt] if a_talkpol > 0 & one == 1, cluster(state_code)
margins, dydx(close_election) post 
	estadd local state_year_fe "Yes"
	estadd local demo_control "Yes" 	 
	estadd local previous_CE "Yes" 	 
	estadd local CE "5" 	 
	estadd local DV "4"
	estadd local rel_type "All"
estimates store m2

replace close_election = 1 - abs_diff
qui logit `DV' i.year i.state_code `demo_controls' close_election  [pw=wt] if a_talkpol > 0 & one == 1, cluster(state_code)
margins, dydx(close_election) post 
	estadd local state_year_fe "Yes"
	estadd local demo_control "Yes" 	 
	estadd local previous_CE "No" 	 
	estadd local CE "linear" 	 
	estadd local DV "4"
	estadd local rel_type "All"
estimates store m3
replace close_election = close_election_5

local DV pol_one_diff4a
qui logit `DV' i.year i.state_code `demo_controls' close_election  [pw=wt] if a_talkpol > 0 & one == 1, cluster(state_code)
margins, dydx(close_election) post 
	estadd local state_year_fe "Yes"
	estadd local demo_control "Yes" 	 
	estadd local previous_CE "No" 	 
	estadd local CE "5" 	 
	estadd local DV "4a"
	estadd local rel_type "All"
estimates store m4

local DV isolation
qui logit `DV' i.year i.state_code `demo_controls' close_election [pw=wt] if a_talkpol > 0 & one == 1, cluster(state_code)
margins, dydx(close_election) post 
	estadd local state_year_fe "Yes"
	estadd local demo_control "Yes" 	 
	estadd local previous_CE "No" 	 
	estadd local CE "5" 	 
	estadd local DV "4"
	estadd local rel_type "All"
estimates store m5

qui logit `DV' i.year i.state_code `demo_controls' close_election lag_close_election [pw=wt] if a_talkpol > 0 & one == 1, cluster(state_code)
margins, dydx(close_election) post 
	estadd local state_year_fe "Yes"
	estadd local demo_control "Yes" 	 
	estadd local previous_CE "Yes" 	 
	estadd local CE "5" 	 
	estadd local DV "4"
	estadd local rel_type "All"
estimates store m6

replace close_election = 1 - abs_diff
qui logit `DV' i.year i.state_code `demo_controls' close_election  [pw=wt] if a_talkpol > 0 & one == 1, cluster(state_code)
margins, dydx(close_election) post 
	estadd local state_year_fe "Yes"
	estadd local demo_control "Yes" 	 
	estadd local previous_CE "No" 	 
	estadd local CE "linear" 	 
	estadd local DV "4"
	estadd local rel_type "All"
estimates store m7

esttab m5 m6 m7 m1 m2 m3 m4 using "./output/table_sensitivity_exposure_all.rtf", replace rtf    ///
	b(%9.3f) se(%9.3f) star(+ 0.10 * 0.05 ** 0.01) ///
		mgroups("Network Isolation" "Cross-cutting Exposure" , pattern(1 0 0 1 0 0 0))  ///
		label legend stats (N state_year_fe demo_control previous_CE CE DV, ///
		fmt(%9.0gc %9.0gc %9.0gc %9.0gc %9.0gc %9.0gc) ///
		label("N" "State-year FE" "baseline controls" "lagged close election" "close election cut-off" "DV specification") ) ///
		varlabels(_cons "Constant")  nonotes 	 ///
		mtitles("model1" "model2" "model3" "model4" "model5" "model6" "model7") 	///
		title("Sensitivity tests on the impact of close elections on exposure to dissent.") 

